<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="商业伙伴ID" prop="bpId">
        <el-input
          v-model="queryParams.bpId"
          placeholder="请输入商业伙伴ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="国家" prop="countryId">
        <el-input
          v-model="queryParams.countryId"
          placeholder="请输入国家"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="省份" prop="provinceId">
        <el-input
          v-model="queryParams.provinceId"
          placeholder="请输入省份"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="市" prop="cityId">
        <el-input
          v-model="queryParams.cityId"
          placeholder="请输入市"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="区县" prop="districtId">
        <el-input
          v-model="queryParams.districtId"
          placeholder="请输入区县"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="街道" prop="street">
        <el-input
          v-model="queryParams.street"
          placeholder="请输入街道"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="地址" prop="address">
        <el-input
          v-model="queryParams.address"
          placeholder="请输入地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="邮编" prop="zipcode">
        <el-input
          v-model="queryParams.zipcode"
          placeholder="请输入邮编"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系人" prop="contactPerson">
        <el-input
          v-model="queryParams.contactPerson"
          placeholder="请输入联系人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="职位" prop="position">
        <el-input
          v-model="queryParams.position"
          placeholder="请输入职位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="电话" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="电话2" prop="phoneExtra">
        <el-input
          v-model="queryParams.phoneExtra"
          placeholder="请输入电话2"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="传真" prop="fax">
        <el-input
          v-model="queryParams.fax"
          placeholder="请输入传真"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机" prop="cellPhone">
        <el-input
          v-model="queryParams.cellPhone"
          placeholder="请输入手机"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="邮件" prop="email">
        <el-input
          v-model="queryParams.email"
          placeholder="请输入邮件"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系人" prop="contactPersonText">
        <el-input
          v-model="queryParams.contactPersonText"
          placeholder="请输入联系人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系人2" prop="contactPerson2">
        <el-input
          v-model="queryParams.contactPerson2"
          placeholder="请输入联系人2"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="职位2" prop="position2">
        <el-input
          v-model="queryParams.position2"
          placeholder="请输入职位2"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="电话2" prop="phone2">
        <el-input
          v-model="queryParams.phone2"
          placeholder="请输入电话2"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="电话3" prop="phoneExtra2">
        <el-input
          v-model="queryParams.phoneExtra2"
          placeholder="请输入电话3"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="传真2" prop="fax2">
        <el-input
          v-model="queryParams.fax2"
          placeholder="请输入传真2"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机2" prop="cellPhone2">
        <el-input
          v-model="queryParams.cellPhone2"
          placeholder="请输入手机2"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="邮件2" prop="email2">
        <el-input
          v-model="queryParams.email2"
          placeholder="请输入邮件2"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系人3" prop="contactPersonText2">
        <el-input
          v-model="queryParams.contactPersonText2"
          placeholder="请输入联系人3"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="启用标志" prop="enabledFlag">
        <el-input
          v-model="queryParams.enabledFlag"
          placeholder="请输入启用标志"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['lease:bpMasterAddress:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['lease:bpMasterAddress:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['lease:bpMasterAddress:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['lease:bpMasterAddress:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="bpMasterAddressList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="地址ID" align="center" prop="addressId"/>
      <el-table-column label="地址类型" align="center" prop="addressType"/>
      <el-table-column label="商业伙伴ID" align="center" prop="bpId"/>
      <el-table-column label="国家" align="center" prop="countryId"/>
      <el-table-column label="省份" align="center" prop="provinceId"/>
      <el-table-column label="市" align="center" prop="cityId"/>
      <el-table-column label="区县" align="center" prop="districtId"/>
      <el-table-column label="街道" align="center" prop="street"/>
      <el-table-column label="地址" align="center" prop="address"/>
      <el-table-column label="邮编" align="center" prop="zipcode"/>
      <el-table-column label="联系人" align="center" prop="contactPerson"/>
      <el-table-column label="职位" align="center" prop="position"/>
      <el-table-column label="电话" align="center" prop="phone"/>
      <el-table-column label="电话2" align="center" prop="phoneExtra"/>
      <el-table-column label="传真" align="center" prop="fax"/>
      <el-table-column label="手机" align="center" prop="cellPhone"/>
      <el-table-column label="邮件" align="center" prop="email"/>
      <el-table-column label="联系人" align="center" prop="contactPersonText"/>
      <el-table-column label="联系人2" align="center" prop="contactPerson2"/>
      <el-table-column label="职位2" align="center" prop="position2"/>
      <el-table-column label="电话2" align="center" prop="phone2"/>
      <el-table-column label="电话3" align="center" prop="phoneExtra2"/>
      <el-table-column label="传真2" align="center" prop="fax2"/>
      <el-table-column label="手机2" align="center" prop="cellPhone2"/>
      <el-table-column label="邮件2" align="center" prop="email2"/>
      <el-table-column label="联系人3" align="center" prop="contactPersonText2"/>
      <el-table-column label="启用标志" align="center" prop="enabledFlag"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['lease:bpMasterAddress:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['lease:bpMasterAddress:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改商业伙伴地址信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="商业伙伴ID" prop="bpId">
          <el-input v-model="form.bpId" placeholder="请输入商业伙伴ID"/>
        </el-form-item>
        <el-form-item label="国家" prop="countryId">
          <el-input v-model="form.countryId" placeholder="请输入国家"/>
        </el-form-item>
        <el-form-item label="省份" prop="provinceId">
          <el-input v-model="form.provinceId" placeholder="请输入省份"/>
        </el-form-item>
        <el-form-item label="市" prop="cityId">
          <el-input v-model="form.cityId" placeholder="请输入市"/>
        </el-form-item>
        <el-form-item label="区县" prop="districtId">
          <el-input v-model="form.districtId" placeholder="请输入区县"/>
        </el-form-item>
        <el-form-item label="街道" prop="street">
          <el-input v-model="form.street" placeholder="请输入街道"/>
        </el-form-item>
        <el-form-item label="地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入地址"/>
        </el-form-item>
        <el-form-item label="邮编" prop="zipcode">
          <el-input v-model="form.zipcode" placeholder="请输入邮编"/>
        </el-form-item>
        <el-form-item label="联系人" prop="contactPerson">
          <el-input v-model="form.contactPerson" placeholder="请输入联系人"/>
        </el-form-item>
        <el-form-item label="职位" prop="position">
          <el-input v-model="form.position" placeholder="请输入职位"/>
        </el-form-item>
        <el-form-item label="电话" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入电话"/>
        </el-form-item>
        <el-form-item label="电话2" prop="phoneExtra">
          <el-input v-model="form.phoneExtra" placeholder="请输入电话2"/>
        </el-form-item>
        <el-form-item label="传真" prop="fax">
          <el-input v-model="form.fax" placeholder="请输入传真"/>
        </el-form-item>
        <el-form-item label="手机" prop="cellPhone">
          <el-input v-model="form.cellPhone" placeholder="请输入手机"/>
        </el-form-item>
        <el-form-item label="邮件" prop="email">
          <el-input v-model="form.email" placeholder="请输入邮件"/>
        </el-form-item>
        <el-form-item label="联系人" prop="contactPersonText">
          <el-input v-model="form.contactPersonText" placeholder="请输入联系人"/>
        </el-form-item>
        <el-form-item label="联系人2" prop="contactPerson2">
          <el-input v-model="form.contactPerson2" placeholder="请输入联系人2"/>
        </el-form-item>
        <el-form-item label="职位2" prop="position2">
          <el-input v-model="form.position2" placeholder="请输入职位2"/>
        </el-form-item>
        <el-form-item label="电话2" prop="phone2">
          <el-input v-model="form.phone2" placeholder="请输入电话2"/>
        </el-form-item>
        <el-form-item label="电话3" prop="phoneExtra2">
          <el-input v-model="form.phoneExtra2" placeholder="请输入电话3"/>
        </el-form-item>
        <el-form-item label="传真2" prop="fax2">
          <el-input v-model="form.fax2" placeholder="请输入传真2"/>
        </el-form-item>
        <el-form-item label="手机2" prop="cellPhone2">
          <el-input v-model="form.cellPhone2" placeholder="请输入手机2"/>
        </el-form-item>
        <el-form-item label="邮件2" prop="email2">
          <el-input v-model="form.email2" placeholder="请输入邮件2"/>
        </el-form-item>
        <el-form-item label="联系人3" prop="contactPersonText2">
          <el-input v-model="form.contactPersonText2" placeholder="请输入联系人3"/>
        </el-form-item>
        <el-form-item label="启用标志" prop="enabledFlag">
          <el-input v-model="form.enabledFlag" placeholder="请输入启用标志"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listBpMasterAddress,
  getBpMasterAddress,
  delBpMasterAddress,
  addBpMasterAddress,
  updateBpMasterAddress
} from "@/api/lease/bpMasterAddress";

export default {
  name: "BpMasterAddress",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商业伙伴地址信息表格数据
      bpMasterAddressList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        addressType: null,
        bpId: null,
        countryId: null,
        provinceId: null,
        cityId: null,
        districtId: null,
        street: null,
        address: null,
        zipcode: null,
        contactPerson: null,
        position: null,
        phone: null,
        phoneExtra: null,
        fax: null,
        cellPhone: null,
        email: null,
        contactPersonText: null,
        contactPerson2: null,
        position2: null,
        phone2: null,
        phoneExtra2: null,
        fax2: null,
        cellPhone2: null,
        email2: null,
        contactPersonText2: null,
        enabledFlag: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询商业伙伴地址信息列表 */
    getList() {
      this.loading = true;
      listBpMasterAddress(this.queryParams).then(response => {
        this.bpMasterAddressList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        addressId: null,
        addressType: null,
        bpId: null,
        countryId: null,
        provinceId: null,
        cityId: null,
        districtId: null,
        street: null,
        address: null,
        zipcode: null,
        contactPerson: null,
        position: null,
        phone: null,
        phoneExtra: null,
        fax: null,
        cellPhone: null,
        email: null,
        contactPersonText: null,
        contactPerson2: null,
        position2: null,
        phone2: null,
        phoneExtra2: null,
        fax2: null,
        cellPhone2: null,
        email2: null,
        contactPersonText2: null,
        enabledFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        refV01: null,
        refV02: null,
        refV03: null,
        refV04: null,
        refV05: null,
        refN01: null,
        refN02: null,
        refN03: null,
        refN04: null,
        refN05: null,
        refD01: null,
        refD02: null,
        refD03: null,
        refD04: null,
        refD05: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.addressId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加商业伙伴地址信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const addressId = row.addressId || this.ids
      getBpMasterAddress(addressId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改商业伙伴地址信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.addressId != null) {
            updateBpMasterAddress(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBpMasterAddress(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const addressIds = row.addressId || this.ids;
      this.$modal.confirm('是否确认删除商业伙伴地址信息编号为"' + addressIds + '"的数据项？').then(function () {
        return delBpMasterAddress(addressIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('lease/bpMasterAddress/export', {
        ...this.queryParams
      }, `bpMasterAddress_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
